/** @file               sw_image.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 447 $
 *  @date               $Date: 2017-02-09 22:56:21 +0800 (周四, 09 2月 2017) $
 */
#ifndef __SW_IMAGE_H__
#define __SW_IMAGE_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef SW_VOID *SW_IMAGE;
#define SW_INVALID_IMAGE NULL

typedef enum _SW_IMAGE_FORMAT
{
    SW_IF_BMP       = 0,
    SW_IF_ICO       = 1,
    SW_IF_JPEG      = 2,
    SW_IF_JNG       = 3,
    SW_IF_KOALA     = 4,
    SW_IF_LBM       = 5,
    SW_IF_IFF       = SW_IF_LBM,
    SW_IF_MNG       = 6,
    SW_IF_PBM       = 7,
    SW_IF_PBMRAW    = 8,
    SW_IF_PCD       = 9,
    SW_IF_PCX       = 10,
    SW_IF_PGM       = 11,
    SW_IF_PGMRAW    = 12,
    SW_IF_PNG       = 13,
    SW_IF_PPM       = 14,
    SW_IF_PPMRAW    = 15,
    SW_IF_RAS       = 16,
    SW_IF_TARGA     = 17,
    SW_IF_TIFF      = 18,
    SW_IF_WBMP      = 19,
    SW_IF_PSD       = 20,
    SW_IF_CUT       = 21,
    SW_IF_XBM       = 22,
    SW_IF_XPM       = 23,
    SW_IF_DDS       = 24,
    SW_IF_GIF       = 25,
    SW_IF_HDR       = 26,
    SW_IF_FAXG3     = 27,
    SW_IF_SGI       = 28,
    SW_IF_EXR       = 29,
    SW_IF_J2K       = 30,
    SW_IF_JP2       = 31,
    SW_IF_PFM       = 32,
    SW_IF_PICT      = 33,
    SW_IF_RAW       = 34,
    SW_IF_YUV420SP  = 200,
    SW_IF_YUV422    = 201,
    SW_IF_INVALID   = -1
}SW_IMAGE_FORMAT;

typedef enum _SW_IMAGE_STYLE
{
    SW_IS_MIRROR,
    SW_IS_FLIP,
    SW_IS_INVALID = -1
}SW_IMAGE_STYLE;

typedef enum _SW_COLOR_SPACE
{
    SW_COS_RGB,
    SW_COS_YUV
}SW_COLOR_SPACE;

typedef struct _SW_COLOR_RGB
{
    SW_UINT8 r;
    SW_UINT8 g;
    SW_UINT8 b;
    SW_UINT8 a;
}SW_COLOR_RGB;

typedef struct _SW_COLOR_YUV
{
    SW_UINT8 y;
    SW_UINT8 u;
    SW_UINT8 v;
    SW_UINT8 a;
}SW_COLOR_YUV;

typedef struct _SW_COLOR
{
    SW_COLOR_SPACE space;
    union
    {
        SW_UINT32 value;
        SW_COLOR_RGB rgb;
        SW_COLOR_YUV yuv;
    }data;
}SW_COLOR;

SW_API SW_RET SW_InitImageAPI(SW_VOID);
SW_API SW_RET SW_RunImageAPI(SW_VOID);
SW_API SW_RET SW_StopImageAPI(SW_VOID);
SW_API SW_RET SW_ExitImageAPI(SW_VOID);
SW_API SW_IMAGE SW_CreateImage(SW_UINT32 width, SW_UINT32 height, SW_UINT32 bpp);
SW_API SW_IMAGE SW_OpenImage(const SW_CHAR *pFileName);
SW_API SW_RET SW_CloseImage(SW_IMAGE image);
SW_API SW_RET SW_SaveImage(SW_IMAGE image, SW_IMAGE_FORMAT format, const SW_CHAR *pFileName);
SW_API SW_RET SW_SetImageStyle(SW_IMAGE image, SW_IMAGE_STYLE style);
SW_API SW_IMAGE_FORMAT SW_GetImageFormat(const SW_CHAR *pFileName);
SW_API SW_UINT32 SW_GetImageBpp(SW_IMAGE image);
SW_API SW_UINT32 SW_GetImageWidth(SW_IMAGE image);
SW_API SW_UINT32 SW_GetImageHeight(SW_IMAGE image);
SW_API SW_UINT32 SW_GetImagePitch(SW_IMAGE image);
SW_API SW_VOID *SW_GetImageInfoPtr(SW_IMAGE image);
SW_API SW_VOID *SW_GetImageBitsPtr(SW_IMAGE image);
SW_API SW_RET SW_GetImagePixel(SW_IMAGE image, SW_UINT32 x, SW_UINT32 y, SW_COLOR_RGB *pRgb);
SW_API SW_RET SW_SetImagePixel(SW_IMAGE image, SW_UINT32 x, SW_UINT32 y, const SW_COLOR_RGB *pRgb);
SW_API const SW_CHAR *SW_GetImageFormatStr(SW_IMAGE_FORMAT format);
SW_API SW_IMAGE SW_ConvertImageToBpp(SW_IMAGE image, SW_UINT32 bpp, SW_BOOL delOld);
SW_API SW_IMAGE SW_RescaleImage(SW_IMAGE image, SW_UINT32 width, SW_UINT32 height, SW_BOOL delOld);
SW_API SW_RET SW_RgbToYuv(SW_COLOR *pColor);
SW_API SW_RET SW_YuvToRgb(SW_COLOR *pColor);

#ifdef __cplusplus
}
#endif

#endif

